﻿///////////////////////////////////////////////////////////
//  Class			:	Block.cs
//  CLRVersion		:	4.0.30319.42000
//  NameSpace		:	BenNHTetris
//  Created on		:	2018/5/31 11:41:27
//  Original author	:	JIYONGFEI 
//  JiYF笨男孩博客  :   https://www.cnblogs.com/JiYF/
///////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace BenNHTetris
{
    public abstract class Block
    {
        protected int _curChangeTimes;  //变化次数
        public int _needRows;           //行数
        public int _needColumns;        //列数
        public int[,] _range;           //变化范围
        public Point _center;           //中心点 相对于必要区域
        public Point _Pos;              //中心点位置,相对于画布


        /// <summary>
        /// 能否变形 ，能变形的条件为在方块的变形范围内不能有其它的方块
        /// </summary>
        /// <param name="arr"></param>
        /// <param name="rows"></param>
        /// <param name="cloumns"></param>
        /// <returns></returns>
        public abstract bool CanChange(int[,] arr ,int rows,int cloumns);

        /// <summary>
        /// 变形
        /// </summary>
        public abstract void Change();

        /// <summary>
        /// 能否左移动
        /// </summary>
        /// <param name="arr"></param>
        /// <param name="rows"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        public abstract bool CanLeftMove(int[,] arr,int rows,int columns);

        /// <summary>
        /// 左移
        /// </summary>
        public void LeftMove()
        {
            _Pos.Y -= 1;
        }

        /// <summary>
        /// 能否右移
        /// </summary>
        /// <param name="arr"></param>
        /// <param name="rows"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        public abstract bool CanRightMove(int[,] arr, int rows, int columns);


        /// <summary>
        /// 右侧移动
        /// </summary>
        public void RightMove()
        {
            _Pos.Y += 1;
        }

        /// <summary>
        /// 能否下移
        /// </summary>
        /// <param name="arr"></param>
        /// <param name="rows"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        public abstract bool CanDownMove(int[,] arr, int rows, int columns);


        /// <summary>
        /// 下侧移动
        /// </summary>
        public void DownMove()
        {
            _Pos.X += 1;
        }


        /// <summary>
        /// 随机生成一个可以通过变形得到的形状
        /// </summary>
        public void RandomShape()
        {
            Random random = new Random();
            this._curChangeTimes = random.Next(4);
            this.Change();
        }

        /// <summary>
        /// 设置中心点相对于画布的位置
        /// </summary>
        /// <param name="x">横向位置</param>
        /// <param name="y">纵向位置</param>
        public void SetCenterPos(int x, int y)
        {
            this._Pos = new Point(x, y);
        }

        /// <summary>
        /// 获取方块出现时中心点的Y轴坐标
        /// </summary>
        /// <returns></returns>
        public abstract int Appear();
    }
}
